/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package doan2database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DongVan
 */
public class TuyenTau_Ve {
        private int m_IDTuyenTau;
	private String m_DiaDiemDi;
	private String m_DiaDiemDen;
	private String m_GioDi;
	private String m_GioDen;
	private String m_GiaVe;
        private String m_NgayDi;
        private int m_IDVe;

        public String getM_NgayDi() {
            return m_NgayDi;
        }

        public void setM_NgayDi(String m_NgayDi) {
            this.m_NgayDi = m_NgayDi;
        }
        
        public int getM_IDVe() {
            return m_IDVe;
        }

        public void setM_IDVe(int m_IDVe) {
            this.m_IDVe = m_IDVe;
        }
	public int getM_IDTuyenTau() {
		return m_IDTuyenTau;
	}
	public void setM_IDTuyenTau(int m_IDTuyenTau) {
		this.m_IDTuyenTau = m_IDTuyenTau;
	}
	public String getM_DiaDiemDi() {
		return m_DiaDiemDi;
	}
	public void setM_DiaDiemDi(String m_DiaDiemDi) {
		this.m_DiaDiemDi = m_DiaDiemDi;
	}
	public String getM_DiaDiemDen() {
		return m_DiaDiemDen;
	}
	public void setM_DiaDiemDen(String m_DiaDiemDen) {
		this.m_DiaDiemDen = m_DiaDiemDen;
	}
	public String getM_GioDi() {
		return m_GioDi;
	}
	public void setM_GioDi(String m_GioDi) {
		this.m_GioDi = m_GioDi;
	}
	public String getM_GioDen() {
		return m_GioDen;
	}
	public void setM_GioDen(String m_GioDen) {
		this.m_GioDen = m_GioDen;
	}
	public String getM_GiaVe() {
		return m_GiaVe;
	}
	public void setM_GiaVe(String m_GiaVe) {
		this.m_GiaVe = m_GiaVe;
	}
	public TuyenTau_Ve(int m_IDTuyenTau, String m_DiaDiemDi, String m_DiaDiemDen,
			String m_GioDi, String m_GioDen, String m_GiaVe,String m_NgayDi, int m_IDVe) {
		this.m_IDTuyenTau = m_IDTuyenTau;
		this.m_DiaDiemDi = m_DiaDiemDi;
		this.m_DiaDiemDen = m_DiaDiemDen;
		this.m_GioDi = m_GioDi;
		this.m_GioDen = m_GioDen;
		this.m_GiaVe = m_GiaVe;
                this.m_NgayDi = m_NgayDi;
		this.m_IDVe = m_IDVe;
	}
	public TuyenTau_Ve(){
		
	}
	
	
	
	AESEncrypt aes = new AESEncrypt();
	Datapro dataprovider = new Datapro();

	
	public ArrayList<TuyenTau_Ve> selected(int tuyenTau, String gioDi) {
                gioDi = aes.encryptString(gioDi);
		String sqlQuery = "select * from TUYEN_TAU inner join VE on TUYEN_TAU.IDTuyenTau = VE.IDTuyen where TUYEN_TAU.IDTuyenTau = "+tuyenTau+" and CONVERT(VARCHAR, TUYEN_TAU.GioDi) = '"+gioDi+"'";
		System.out.println(sqlQuery);
                ArrayList<TuyenTau_Ve> listTuyenTau_Ve = new ArrayList<TuyenTau_Ve>();
		ResultSet rs = dataprovider.Selected(sqlQuery);
		try {
			while (rs.next()) {
				TuyenTau_Ve ttv = new TuyenTau_Ve();
				ttv.m_IDTuyenTau = rs.getInt(1);
				ttv.m_DiaDiemDi = aes.decryptString(rs.getString(2));
				ttv.m_DiaDiemDen = aes.decryptString(rs.getString(3));
				ttv.m_GioDi = aes.decryptString(rs.getString(4));
				ttv.m_GioDen = aes.decryptString(rs.getString(5));
				ttv.m_GiaVe = aes.decryptString(rs.getString(6));
                                ttv.m_IDVe = rs.getInt(8);
                                ttv.m_NgayDi = aes.decryptString(rs.getString(10));
				listTuyenTau_Ve.add(ttv);
			}
			dataprovider.disconnect();
	        rs.close();
	        return listTuyenTau_Ve;
	        
	    } catch ( SQLException ex) {
	        Logger.getLogger(Datapro.class.getName()).log(Level.SEVERE, null, ex);
	    }
		return null;
	}
	

	
}
